home *** CD-ROM | disk | FTP | other *** search
- //--------------------------------------------------------------
- //
- // Generic.wfm
- //
- // Run this form to connect to a BDE alias and create
- // a data entry form for that data source. This form
- // can create and populate a small sample table on
- // SQL database servers such as Oracle, Sybase, and
- // InterBase. It can also works with dBASE tables
- // if you connect to a standard BDE alias.
- //
- // Dependencies: BDE alias with table creation rights.
- //
- // Visual dBASE Samples Group
- //
- // $Revision: 1.13 $
- //
- // Copyright (c) 1997, Borland International, Inc.
- // All rights reserved.
- //
- //---------------------------------------------------------------
-
- #include "bde4api.h"
- #define PAGE_ALIAS 1
- #define PAGE_PASSWORD 2
- #define PAGE_DATA 3
- #define PAGE_ERROR 4
- #define BACKSPACE_KEY 8 /* ASCII value of Backspace key */
- #define TAB_KEY 9 /* ASCII value of Backspace key */
- #define DELETE_KEY 127 /* ASCII value of Delete key */
-
- SET TALK OFF
- ** END HEADER -- do not remove this line
- //
- // Generated on 10/20/97
- //
- parameter bModal
- local f
- f = new genericForm()
- if (bModal)
- f.mdi = false // ensure not MDI
- f.readModal()
- else
- f.open()
- endif
-
- class genericForm of FORM
- set procedure to ( _dbwinhome + "CUSTOM\DATABUTTONS.CC" ) additive
- with (this)
- open = class::FORM_OPEN
- scaleFontSize = 8
- scaleFontBold = false
- height = 14
- left = 6
- top = 2
- width = 72
- text = "Generic Data Entry Form"
- background = "filename gdiag.jpg"
- endwith
-
-
- this.SESSION1 = new SESSION()
- this.SESSION1.parent = this
- with (this.SESSION1)
- left = 0
- top = 0
- lockRetryInterval = 0
- endwith
-
-
- this.DATABASE1 = new DATABASE()
- this.DATABASE1.parent = this
- with (this.DATABASE1)
- left = 4
- top = 0
- databaseName = "VDBSAMPLE"
- session = form.SESSION1
- active = true
- endwith
-
-
- this.SAMPLE1 = new QUERY()
- this.SAMPLE1.parent = this
- with (this.SAMPLE1)
- left = 66
- top = 1
- database = form.database1
- sql = 'SELECT * FROM "Sample.dbf"'
- active = true
- endwith
-
-
-
-
- this.LINE1 = new LINE(this)
- with (this.LINE1)
- left = 70
- right = 2
- top = 2.75
- bottom = 2.75
- width = 2
- metric = 0
- colorNormal = "darkblue"
- pageno = 0
- endwith
-
-
- this.LABELSELECTDB = new TEXT(this)
- with (this.LABELSELECTDB)
- height = 0.8
- left = 4
- top = 3.5
- width = 20
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Select a database alias:"
- endwith
-
-
- this.COMBODATASOURCE = new COMBOBOX(this)
- with (this.COMBODATASOURCE)
- height = 1.0909
- left = 28
- top = 3.5
- width = 30
- metric = 0
- fontSize = 8
- style = 2
- endwith
-
-
- this.BUTTONOPEN = new PUSHBUTTON(this)
- with (this.BUTTONOPEN)
- onClick = class::BUTTONOPEN_ONCLICK
- height = 1.2
- left = 4
- top = 5.5
- width = 12
- text = "Open"
- metric = 0
- fontSize = 8
- group = true
- value = false
- endwith
-
-
- this.CHECKCREATE = new CHECKBOX(this)
- with (this.CHECKCREATE)
- transparent = true
- height = 1
- left = 5
- top = 8
- width = 63
- text = "Create DBASEGEN table (requires 'create' rights)"
- metric = 0
- colorNormal = "WindowText/BtnFace"
- fontName = "Arial"
- fontSize = 9
- value = true
- group = true
- endwith
-
-
- this.HELP1 = new TEXT(this)
- with (this.HELP1)
- height = 2
- left = 5
- top = 10
- width = 62
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "You can use this form as a sample data entry form for any data source connected through a valid BDE alias. "
- endwith
-
-
- this.LABELALIAS = new TEXT(this)
- with (this.LABELALIAS)
- height = 0.9
- left = 4
- top = 0.5
- width = 18
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Current database alias:"
- pageno = 0
- endwith
-
-
- this.VALUEALIAS = new TEXT(this)
- with (this.VALUEALIAS)
- height = 0.9
- left = 23
- top = 0.5
- width = 29
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- fontBold = true
- fontItalic = true
- text = "none"
- pageno = 0
- endwith
-
-
- this.LABELDRIVER = new TEXT(this)
- with (this.LABELDRIVER)
- height = 0.9
- left = 4
- top = 1.5
- width = 18
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Driver:"
- pageno = 0
- endwith
-
-
- this.VALUEDRIVER = new TEXT(this)
- with (this.VALUEDRIVER)
- height = 0.9
- left = 23
- top = 1.5
- width = 29
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- fontBold = true
- fontItalic = true
- text = "STANDARD"
- pageno = 0
- endwith
-
-
- this.BUTTONDATABACK = new PUSHBUTTON(this)
- with (this.BUTTONDATABACK)
- onClick = class::BUTTONDATABACK_ONCLICK
- height = 1.2
- left = 54
- top = 0.5
- width = 14
- text = "Change Alias"
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.LABELID = new TEXT(this)
- with (this.LABELID)
- height = 1
- left = 14
- top = 7
- width = 11
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Client ID:"
- pageno = 3
- endwith
-
-
- this.ENTRYID = new ENTRYFIELD(this)
- with (this.ENTRYID)
- height = 1
- left = 28
- top = 7
- width = 12
- metric = 0
- colorHighLight = ""
- fontSize = 8
- value = "entryID"
- validRequired = true
- pageno = 3
- borderStyle = 7
- endwith
-
-
- this.LABELCONTACT = new TEXT(this)
- with (this.LABELCONTACT)
- height = 1
- left = 14
- top = 8
- width = 11
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Contact:"
- pageno = 3
- endwith
-
-
- this.ENTRYCONTACT = new ENTRYFIELD(this)
- with (this.ENTRYCONTACT)
- height = 1
- left = 28
- top = 8
- width = 32
- metric = 0
- colorHighLight = ""
- fontSize = 8
- value = "entryContact"
- validRequired = true
- pageno = 3
- borderStyle = 7
- endwith
-
-
- this.LABELCOMPANY = new TEXT(this)
- with (this.LABELCOMPANY)
- height = 1
- left = 14
- top = 9
- width = 11
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Company:"
- pageno = 3
- endwith
-
-
- this.ENTRYCOMPANY = new ENTRYFIELD(this)
- with (this.ENTRYCOMPANY)
- height = 1
- left = 28
- top = 9
- width = 32
- metric = 0
- colorHighLight = ""
- fontSize = 8
- value = "entryCompany"
- validRequired = true
- pageno = 3
- borderStyle = 7
- endwith
-
-
- this.LABELEMAIL = new TEXT(this)
- with (this.LABELEMAIL)
- height = 0.8
- left = 14
- top = 10
- width = 11
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "E-Mail:"
- pageno = 3
- endwith
-
-
- this.ENTRYEMAIL = new ENTRYFIELD(this)
- with (this.ENTRYEMAIL)
- height = 1
- left = 28
- top = 10
- width = 32
- metric = 0
- colorHighLight = ""
- fontSize = 8
- value = "entryEMail"
- validRequired = true
- pageno = 3
- borderStyle = 7
- endwith
-
-
- this.LABELPHONE = new TEXT(this)
- with (this.LABELPHONE)
- height = 1
- left = 14
- top = 11
- width = 11
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 9
- text = "Phone:"
- pageno = 3
- endwith
-
-
- this.ENTRYPHONE = new ENTRYFIELD(this)
- with (this.ENTRYPHONE)
- height = 1
- left = 28
- top = 11
- width = 22
- metric = 0
- colorHighLight = ""
- fontSize = 8
- value = "entryPhone"
- validRequired = true
- pageno = 3
- borderStyle = 7
- endwith
-
-
- this.BUTTONERRORBACK = new PUSHBUTTON(this)
- with (this.BUTTONERRORBACK)
- onClick = class::BUTTONERRORBACK_ONCLICK
- height = 1.2
- left = 32
- top = 11
- width = 11
- text = "OK"
- metric = 0
- fontSize = 8
- group = true
- pageno = 4
- value = false
- endwith
-
-
- this.ERRORMSG = new TEXT(this)
- with (this.ERRORMSG)
- height = 6
- left = 4
- top = 3.5
- width = 64
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontName = "Arial"
- fontSize = 8
- fontBold = true
- text = "Error!"
- pageno = 4
- endwith
-
-
- this.LABELPASSWORD = new TEXT(this)
- with (this.LABELPASSWORD)
- height = 1
- left = 12
- top = 6
- width = 12
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontSize = 9
- text = "Password:"
- pageno = 2
- endwith
-
-
- this.LABELUSERNAME = new TEXT(this)
- with (this.LABELUSERNAME)
- height = 1
- left = 12
- top = 4
- width = 12
- metric = 0
- colorNormal = "BtnText"
- transparent = true
- fontSize = 9
- text = "User Name:"
- pageno = 2
- endwith
-
-
- this.ENTRYUSER = new ENTRYFIELD(this)
- with (this.ENTRYUSER)
- height = 1
- left = 26
- top = 4
- width = 20
- metric = 0
- colorHighLight = ""
- fontSize = 8
- value = ""
- validRequired = true
- pageno = 2
- borderStyle = 7
- endwith
-
-
- this.PASSWORD1 = new ENTRYFIELD(this)
- with (this.PASSWORD1)
- onOpen = {; this.hiddenValue = ""}
- key = class::PASSWORD1_KEY
- height = 1
- left = 26
- top = 6
- width = 20
- metric = 0
- colorHighLight = ""
- fontSize = 8
- fontBold = true
- value = ""
- validRequired = true
- pageno = 2
- borderStyle = 7
- endwith
-
-
- this.BUTTONOK = new PUSHBUTTON(this)
- with (this.BUTTONOK)
- onClick = class::BUTTONOK_ONCLICK
- height = 1.1818
- left = 14
- top = 8.5
- width = 11
- text = "OK"
- metric = 0
- fontSize = 8
- group = true
- pageno = 2
- value = false
- endwith
-
-
- this.BUTTONCANCEL = new PUSHBUTTON(this)
- with (this.BUTTONCANCEL)
- onClick = class::BUTTONCANCEL_ONCLICK
- height = 1.2
- left = 28
- top = 8.5
- width = 11
- text = "Cancel"
- metric = 0
- fontSize = 8
- group = true
- pageno = 2
- value = false
- endwith
-
-
- this.BUTTONFIRST1 = new BUTTONFIRST(this)
- with (this.BUTTONFIRST1)
- height = 1.1818
- left = 10
- top = 5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONNEXT1 = new BUTTONNEXT(this)
- with (this.BUTTONNEXT1)
- height = 1.1818
- left = 36
- top = 5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONLAST1 = new BUTTONLAST(this)
- with (this.BUTTONLAST1)
- height = 1.1818
- left = 49
- top = 5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONPREVIOUS1 = new BUTTONPREVIOUS(this)
- with (this.BUTTONPREVIOUS1)
- height = 1.1818
- left = 23
- top = 5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONAPPEND1 = new BUTTONAPPEND(this)
- with (this.BUTTONAPPEND1)
- height = 1.2
- left = 10
- top = 3.5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONSAVE1 = new BUTTONSAVE(this)
- with (this.BUTTONSAVE1)
- height = 1.1818
- left = 36
- top = 3.5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONDELETE1 = new BUTTONDELETE(this)
- with (this.BUTTONDELETE1)
- height = 1.1818
- left = 23
- top = 3.5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.BUTTONABANDON1 = new BUTTONABANDON(this)
- with (this.BUTTONABANDON1)
- height = 1.1818
- left = 49
- top = 3.5
- width = 12
- metric = 0
- fontSize = 8
- group = true
- pageno = 3
- value = false
- endwith
-
-
- this.rowset = this.sample1.rowset
-
- // {Linked Method} form.open
- function Form_open
- // Fill the select list with alias names.
-
- // If running as a compiled app, check
- // for strucmem.dll
- if ( "runtime" $ LOWER( VERSION(0) ) )
- this.mdi := false
- if ( ( not FILE("strucmem.dll") ) and FILE("strucmem.dll",true) )
- COPY FILE "strucmem.dll" TO "strucmem.dll"
- endif
- endif
-
- class::getAliasArrays()
- this.comboDataSource.dataSource := "array form.BDEAlias"
- if ( this.BDEAlias.size > 0 )
- this.comboDataSource.value := this.BDEAlias[1]
- endif
- return ( GENERICFORM::OPEN() )
-
- function getAliasArrays()
- // Get a list of alias names from BDE.
- local sName, sDriver
- local nBDECursor, nResult, structDBD
- DO "bde4api.prg"
-
- sName = ""
- sDriver = ""
- nBDECursor = 0
- nResult = 0
- structDBD = new StructDBDesc()
-
- this.BDEAlias = new Array()
- this.BDEDriver = new AssocArray()
- nResult := DbiOpenDatabaseList( nBDECursor )
-
- do while ( nResult == DBIERR_NONE )
- nResult := ;
- DbiGetNextRecord( nBDECursor, dbiNOLOCK, ;
- structDBD.value, BDENULL)
-
- if ( nResult == DBIERR_NONE )
- sName := structDBD.getMember("szName")
- sDriver := structDBD.getMember("szDbName")
- this.BDEAlias.add( sName )
- this.BDEDriver[ sName ] := sDriver
- endif
-
- this.BDEAlias.sort()
- enddo
- nResult := DbiCloseCursor( nBDECursor )
- return ( nResult )
-
- function OpenDatabase()
- // Try to open the database.
- // Catch errors to handle bad passwords and
- // unavailable servers.
- local sError, bConnected
- sError = ""
- bConnected = false
-
- this.form.db = new Database()
- this.form.dbasegen1 = new Query()
- with ( this.form.db )
- databaseName := RTRIM(this.form.comboDataSource.value)
- loginString := RTRIM(this.form.entryUser.value) + "/" + ;
- RTRIM(this.form.password1.hiddenValue)
- endwith
- try
- this.form.db.active = true
- if ( this.form.checkcreate.value )
- class::CreateTable()
- // refresh connection to see new table.
- this.form.db.active := false
- this.form.db.active := true
- endif
- class::LinkQuery()
- catch (DbException e)
- sError := "Server Errors: <BR> "
- for i = 1 to e.errors.size
- sError += e.errors[i].message + " <BR> "
- next
- class::GoPageError( sError )
-
- catch (Exception e)
- class::GoPageError( e.message );
-
- finally
- bConnected := ( this.form.db.active and ;
- this.form.dbasegen1.active )
- endtry
- return ( bConnected )
-
- // {Linked Method} form.password1.key
- function PASSWORD1_key( nChar, nPosition, bShift, bControl)
- local nShowChar, sChar
- nShowChar = nChar
- sChar = CHR( nChar )
- do case // Check for keys that modify the value
- case ( nChar == BACKSPACE_KEY )
- this.hiddenValue := STUFF( this.hiddenValue, nPosition - 1, 1, "")
- case ( nChar == DELETE_KEY )
- this.hiddenValue := STUFF( this.hiddenValue, nPosition, 1, "")
- case ( nChar < 32 )
- // control key
- otherwise
- if ( isalpha(sChar) or ( sChar >= "0" and sChar <= "9" ) )
- this.hiddenValue := ;
- STUFF( this.hiddenValue, nPosition, 1, sChar )
- nShowChar = ASC('*')
- endif
-
- endcase
- return ( nShowChar )
-
- function GoPageError( sMessage )
- this.form.errorMsg.text := "<h3>" + sMessage + "</h3>"
- this.form.pageno := PAGE_ERROR
- return ( this.form.pageno )
-
- function CreateTable
- // Create a populate a simple table.
- local bCreate
- bCreate = false
- if ( NOT this.form.db.tableExists("DBASEGEN") )
- bCreate := this.form.db.executeSQL( ;
- "CREATE TABLE DBASEGEN (CLIENTID CHAR(10), " + ;
- "COMPANY CHAR(30), " + ;
- "CONTACT CHAR(30), " + ;
- "EMAIL CHAR(30), " + ;
- "PHONE CHAR(20))")
- class::InsertData("'C1010','THE BURROUGHS GROUP','CHRIS BURROUGHS','CB@TBG.COM','415-555-4220'")
- class::InsertData("'C1020','CATFISH INTERNATIONAL','BRENDA SMITH','BSMITH@CATFISH.COM','306-555-7275'")
- class::InsertData("'C1030','GROUP TWO','ROB BOWMAN','RBOWMAN@AYE.NET','206-555-8080'")
- class::InsertData("'C1040','XFAX CORPORATION','JOE FRITSCH','JOE@CROP.XFAX.COM','808-555-2600'")
- class::InsertData("'C1050','SIGNS INC','TINA MASTERSON','TINA@SINC.COM','808-555-5231'")
- endif
- return ( bCreate )
-
- function InsertData( sValues )
- // Insert field values into a new record.
- local bInsert
- bInsert = this.form.db.executeSQL( ;
- "INSERT INTO DBASEGEN " + ;
- "(CLIENTID, COMPANY, CONTACT, EMAIL, PHONE) VALUES " + ;
- "(" + sValues + ")" )
- return ( bInsert )
-
- function LinkQuery
- // Create a query and link it to the Text controls.
- local fGen
- fGen = null
-
- with (this.form.dbasegen1)
- database = this.form.db
- sql = "SELECT * FROM DBASEGEN"
- active = true
- endwith
-
- this.form.rowset := this.form.dbasegen1.rowset
- fGen := this.form.dbasegen1.rowset.fields
- this.form.entryID.dataLink := fGen["CLIENTID"]
- this.form.entryCompany.dataLink := fGen["COMPANY"]
- this.form.entryContact.dataLink := fGen["CONTACT"]
- this.form.entryEMail.dataLink := fGen["EMAIL"]
- this.form.entryPhone.dataLink := fGen["PHONE"]
- return ( this.form.dbasegen1.active )
-
- // {Linked Method} form.buttonopen.onClick
- function buttonOpen_onClick
- // If the database is not a native BDE database, go to the
- // password page, otherwise try to open the alias.
- this.form.valueAlias.text := this.form.comboDataSource.value
- this.form.valueDriver.text := ;
- this.form.BDEDriver[ this.form.comboDataSource.value ]
- this.form.entryUser.value := ""
- this.form.password1.value := ""
- if ( this.form.valueDriver.text == "STANDARD" )
- if ( class::OpenDatabase() )
- this.form.pageno := PAGE_DATA
- endif
- else
- this.form.pageno := PAGE_PASSWORD
- endif
- return ( this.form.pageno )
-
- // {Linked Method} form.buttonerrorback.onClick
- function buttonErrorBack_onClick
- // Go back to page 1.
- this.form.pageno := PAGE_ALIAS
- return ( this.form.pageno )
-
- // {Linked Method} form.buttondataback.onClick
- function buttonDataBack_onClick
- // Close the database and query and clear links.
-
- this.form.entryID.dataLink := null
- this.form.entryCompany.dataLink := null
- this.form.entryContact.dataLink := null
- this.form.entryEMail.dataLink := null
- this.form.entryPhone.dataLink := null
-
- this.form.rowset := null
- this.form.dbasegen1.active := false
- this.form.db.active := false
- this.form.pageno := PAGE_ALIAS
- return ( this.form.pageno )
-
- // {Linked Method} form.buttoncancel.onClick
- function buttonCancel_onClick
- // Go back to page one from password page.
- this.form.pageno := PAGE_ALIAS
- return ( this.form.pageno )
-
- // {Linked Method} form.buttonok.onClick
- function buttonOK_onClick
- // Try using password.
- if ( class::OpenDatabase() )
- this.form.pageno := PAGE_DATA
- endif
- return ( this.form.pageno )
- endclass
-